package com.desksoft.ecommerce.util.remoteio.realize;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.desksoft.ecommerce.util.remoteio.RemoteIOUtil;
import com.sun.xfile.XFile;
import com.sun.xfile.XFileInputStream;
import com.sun.xfile.XFileOutputStream;

/***************************************
 * <pre>
 * 版权所有：杭州迪科软件 保留所有权利
 * 创建日期: Jun 28, 2011 4:49:34 PM
 * 创建作者：luoy
 * 文件名称：远程文件IO工具实现类	NFS实现
 * 版本：
 * 功能：
 * 最后修改时间：Jun 28, 2011 4:49:34 PM
 * 修改记录：
 * </pre>
 *****************************************/
public class NfsRemoteIOUtil extends RemoteIOUtil {

	protected String url;		// 远程url  nfs://192.168.168.74/rootdir/
	
	@Override
	public void initRemote(){
		this.url = "nfs://" + host + rootDir + "/";
	}
	
	@Override
	public InputStream getInputStream(String path) throws IOException {
		InputStream inputStream = new XFileInputStream(this.url + path);
		return inputStream;
	}

	@Override
	public OutputStream getOutputStream(String path) throws IOException {
		OutputStream outputStream = new XFileOutputStream(this.url + path);
		return outputStream;
	}

	@Override
	public String[] browerDir(String path) throws IOException {
		XFile xfile = new XFile(this.url+path);
		if (!xfile.exists()){
			throw new IOException(this.url+path+" 指向的文件不存在.");
		}
		if (!xfile.isDirectory()){
			throw new IOException(this.url+path+" 指向的是文件而不是目录.");
		}
		return xfile.list();
	}

	@Override
	public String mkDir(String path) throws IOException {
		
		XFile xfile = new XFile(this.url+path);
		if (xfile.exists()){
			throw new IOException(this.url+path+" 指向的目录已经存在.");
		}
		xfile.mkdirs();
		
		return this.url+path;
	}

	@Override
	public boolean delPath(String path) throws IOException {
		
		XFile xfile = new XFile(this.url+path);
		if (!xfile.exists()){
			throw new IOException(this.url+path+" 指向的目录不存在.");
		}
		return xfile.delete();
	}

	@Override
	public boolean exists(String path) {
		XFile xfile = new XFile(this.url+path);
		return xfile.exists();
	}

	/* (non-Javadoc)
	 * @see com.desksoft.ecommerce.util.remoteio.RemoteIOUtil#disconnect()
	 */
	@Override
	public void disconnect() {
		// TODO Auto-generated method stub
		
	}

}
